/**
 * Created by wurenjie on 15/12/16.
 */
var __ROOT__ = 'http://localhost';

$(function(){
    // console.log(g_config={wgateid: "{$wgateid}"});
    var client = new HproseHttpClient(__ROOT__+'/shu_ces_wechat/hprose.php/User', ['getBindState']);
    client.getBindState("oXQ7gt5_dUyaoP1qN6in3axC-xWw",function(result){
        result = JSON.parse(result);
        if(result.state == 2 ||result.state == 3)
        {
            alert('您已绑定成功！');
        }
    });
    $("#confirm_login").click(function(){
        var sid = $("#sid").val();
        if(/^\d{8}$/.test(sid) == false){
            alert("请输入正确学号！");
            $("#sid").focus();
            return false;
        }

        var pwd = $("#pwd").val();
        // console.log(sid+pwd+"{$wgateid}");
        var client = new HproseHttpClient(__ROOT__+'/shu_ces_wechat/hprose.php/User', ['bind']);
        client.bind(sid,pwd,"oXQ7gt5_dUyaoP1qN6in3axC-xWw",function(result){
            result = JSON.parse(result);
            // console.log(result);
            if(result.success != 0){
                document.location = __ROOT__+"/shu_ces_wechat/index/bindInfo";
            }
            else{
                alert(result.info);
            }
        });
    })
    //bindInfo
    $('#datetimepicker').datetimepicker({
        minView: "month", //选择日期后，不会再跳转去选择时分秒
        format: "yyyy-mm-dd", //选择日期后，文本框显示的日期格式
        language: 'zh-CN', //汉化
        autoclose:true ,//选择日期后自动关闭
    });
    var ssid= BASE64.decoder("12122775");//返回会解码后的unicode码数组。
    var sid = '';
    for(var i = 0 , len =  ssid.length ; i < len ;++i){
        sid += String.fromCharCode(ssid[i]);
    }
    var uuid= BASE64.decoder("13");//返回会解码后的unicode码数组。
    var uid = '';
    for(i = 0 , len =  uuid.length ; i < len ;++i){
        uid += String.fromCharCode(uuid[i]);
    }
    var client = new HproseHttpClient(__ROOT__+'/shu_ces_wechat/hprose.php/User', ['getIniPersonInfo']);
    client.getIniPersonInfo(sid,function(result) {
        result = JSON.parse(result);
        // console.log(result.result.name);
        if(result.success == 1){
            $("#sid").html(result.result.id);
            $("#ssid").val(result.result.id);
//                if(result.result.name != null)
//                    $("#name").html(result.result.name);

        }
    });
});
